package com.raising.sc.log.server.rabbit;

import com.alibaba.fastjson.JSON;
import com.raising.sc.log.server.entity.ApiLog;
import com.raising.sc.log.server.service.ApiLogServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * 接收者
 * @author GaoYuan
 * @date 2018/4/9 下午3:55
 */
@Component
public class Receiver {

    private CountDownLatch latch = new CountDownLatch(1);

    @Autowired
    ApiLogServerService apiLogService;

    public void receiveMessage(String message) {
        System.out.println("Received <" + message + ">");
        if(!"Hello from RabbitMQ!".equals(message)){
            ApiLog apiLog=  JSON.parseObject(message,ApiLog.class);
            apiLogService.saveLogger(apiLog);
            latch.countDown();
        }
    }


}